package com.workflow.engine.eb.util;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/6/7.
 */
public class BizMethodUtil {

    public static String createLoginQueryString(final String uuid) {
        String queryString = "";
        try {
            Map<String, String> queryStringMap = new HashMap<String, String>() {{
                put("uuid", uuid);
//                put("ReturnUrl", createLoginReturnUrl());
                put("r", "0.5913792195467515");
                put("version", "2015");
            }};
            queryString = MapUtil.getQueryStringFromMap(queryStringMap, false);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return queryString;
    }

    public static String createLoginReturnUrl() throws UnsupportedEncodingException {
        Map<String, String> urlParam = new HashMap<String, String>(){{
            put("cu", "true");
            put("utm_source", "baidu-pinzhuan");
            put("utm_medium", "cpc");
            put("utm_campaign", "t_288551095_baidupinzhuan");
            put("utm_term", "0f3d30c8dba7459bb52f2eb5eba8ac7d_0_69c516e072c0497283c8548d47b6643d");
        }};
        return "https://www.jd.com" + MapUtil.getQueryStringFromMap(urlParam, true);
    }

    public static String jsonEncode(String source) {
        if (source == null) {
            return "";
        }
        String html = "";
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < source.length(); i++) {
            char c = source.charAt(i);
            switch (c) {
                case '<':
                    buffer.append("&lt;");
                    break;
                case '>':
                    buffer.append("&gt;");
                    break;
                case '&':
                    buffer.append("&amp;");
                    break;
//                case '"':
//                    buffer.append("&quot;");
//                    break;
                case 13:
                    break;
                default:
                    buffer.append(c);
            }
        }
        html = buffer.toString();
        return html;
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
//        createLoginReturnUrl();
        System.out.println(createLoginQueryString("abc"));
    }
}
